<!DOCTYPE html>
<html>
    <head>
        <title>cppWebSockets multipoll example</title>
        <meta name="author"    value="jason@jasonkruse.com" />
        <meta name="licsense"  value="BSD" />
        <meta name="robots"    value="none" />
        <style type="text/css">
            * { margin: 5px; }
        </style>
    </head>
    <body>
        <h3>Multi Poll server</h3>
        <div>
            <p>
                A basic example of how to implement a WebSocketServer <i>and</i> listen to other
               fds.
            </p><br />
            <p>
               This is useful when your server needs to handle connections from 
               WebSocket clients and other TCP connections at the same time.
            </p>
            <ul><br />
                <li>Compile and run the server in examples/multiPollServer.</li>
                <li>
                    Enter messages into standard input and they will be sent out to
                    all connected clients.
                </li>
            </ul>
            <p><br />
                <i>Note: </i>
                There is no flash fallback, so make sure you have a modern browser with
                WebSocket support.
            </p>
        </div>
        <fieldset>
            <legend>Demo</legend>
            <div><u>Server messages</u></div>
            <div id="output"></div>
        </fieldset>
        
        <script type="text/javascript">
            // Putting the js here after the dom is available in the browser because not using a framework
            var PORT = 8080;
            var ws = new WebSocket("ws://localhost:" + PORT );
            var output   = document.getElementById("output");

            ws.onmessage = function( evt ){
                addMessage( evt.data );
            };

            ws.onerror = function( evt ) { 
                addMessage( '<i>WebSocket error :(</i>' );
            };

            ws.onopen = function( evt ) { 
                addMessage( '<i>Connected</i>' );
            };

            ws.onclose = function( evt ) { 
                addMessage( '<i>Disconnected</i>' );
            };

            function addMessage( msg ){
                output.innerHTML += msg + '<br />'; 
            }
        </script>
    </body>
</html>

